//
//  StartViewController.m
//  TianTianKankan
//
//  Created by sunmingming on 14-8-21.
//  Copyright (c) 2014年 Ebola. All rights reserved.
//

#import "StartViewController.h"
#import "AppDelegate.h"
#import "tooles.h"
#import "AppDelegate.h"

@interface StartViewController ()

@property(nonatomic,strong) UIImageView *bgView;
@property(nonatomic,strong) UIImageView *titleView;

@property(nonatomic,strong) UILabel *versionLabel;
@property(nonatomic,strong) UIButton *insertButton;
@property(nonatomic,strong) UIButton *helpButton;
@property(nonatomic,strong) UILabel *rightLabel;

-(void)buttonPressed:(id)sender;

@end

@implementation StartViewController

@synthesize versionLabel = _versionLabel;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = @"百家姓";
        
        self.bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cover.jpg"]];
        self.bgView.contentMode = UIViewContentModeScaleToFill;
        [self.view addSubview:self.bgView];
        
        self.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"title.png"]];
        self.titleView.contentMode = UIViewContentModeScaleToFill;
        [self.view addSubview:self.titleView];

        self.versionLabel = [UILabel new];
        self.versionLabel.text = @"【版本2.0.0】";
        self.versionLabel.numberOfLines = 1;
        self.versionLabel.textColor = [UIColor blackColor];
        self.versionLabel.font = [UIFont fontWithName:@"Arial" size:17.0f];
        self.versionLabel.textAlignment = NSTextAlignmentCenter;
        [self.view addSubview:self.versionLabel];
        
        self.insertButton = [[UIButton alloc] init];
        self.insertButton.tag = 1;
        [self.insertButton setImage:[UIImage imageNamed:@"style2_button_catalog_normal.png"] forState:UIControlStateNormal];
        [self.insertButton setImage:[UIImage imageNamed:@"style2_button_catalog_pressed.png"] forState:UIControlStateHighlighted];
        [self.insertButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:self.insertButton];
        
        self.helpButton = [[UIButton alloc] init];
        self.helpButton.tag = 2;
        [self.helpButton setImage:[UIImage imageNamed:@"style2_button_help_normal.png"] forState:UIControlStateNormal];
        [self.helpButton setImage:[UIImage imageNamed:@"style2_button_help_pressed.png"] forState:UIControlStateHighlighted];
        [self.helpButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:self.helpButton];
        
        self.rightLabel = [UILabel new];
        self.rightLabel.text = @"CopyRight @xiaoluoli.com";
        self.rightLabel.numberOfLines = 1;
        self.rightLabel.backgroundColor = TitleColor;
        self.rightLabel.textColor = [UIColor whiteColor];
        self.rightLabel.font = [UIFont fontWithName:@"Arial" size:17.0f];
        self.rightLabel.textAlignment = NSTextAlignmentCenter;
        [self.view addSubview:self.rightLabel];
        
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    WS(ws);
    //TODO use masonry to re-frame all the subviews.
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(ws.view);
    }];
    
    [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(self.titleView.intrinsicContentSize);
        make.centerX.mas_equalTo(ws.view);
        make.top.mas_equalTo(ws.view);
    }];
    
    [self.versionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(ws.view);
        make.centerX.mas_equalTo(ws.view);
        make.top.mas_equalTo(self.titleView.mas_bottom).with.offset(10);
        make.height.mas_equalTo(20);
    }];
    
    [self.insertButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(self.insertButton.intrinsicContentSize);
        make.centerX.mas_equalTo(ws.view);
        make.top.mas_equalTo(self.versionLabel.mas_bottom).with.offset(40);
    }];
    
    [self.helpButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(self.helpButton.intrinsicContentSize);
        make.centerX.mas_equalTo(ws.view);
        make.top.mas_equalTo(self.insertButton.mas_bottom).with.offset(40);
    }];
    
    [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(ws.view);
        make.centerX.mas_equalTo(ws.view);
        make.bottom.mas_equalTo(ws.view);
        make.height.mas_equalTo(60);
    }];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)buttonPressed:(id)sender
{
    NSLog(@"buttonPressed :%d",[sender tag]);
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    [APPALL startWithDrawerIndex:[sender tag]];
}

@end
